<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/js/util.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
    <style>
        .btn {
            font-size: 12px;
        }

        .lay-box {
            padding: 10px;
        }
        .layui-form-checkbox[lay-skin=primary] i{
            top: 5px;
        }
    </style>
</head>
<body>
<title>评论任务</title>
<div class="lay-box">
    <div class="layui-inline" style="float: left">
        <button class="layui-btn" onclick="gradeEdit()">
            <i class="layui-icon">&#xe608;</i> 发布任务
        </button>
        <button class="layui-btn" onclick="search()" style="float: left;margin-left:20px">
            <i class="layui-icon">&#xe669;</i> 刷新
        </button>
        <button class="layui-btn" onclick="checkData()" style="float: left;margin-left:20px">
            <i class="layui-icon">&#xe669;</i> 导入新表数据
        </button>
    </div>
    <div class="layui-inline">
        <label style="height: 30px">任务状态:</label>
        <select id="status" lay-verify="" style="width: 150px;height: 30px" >
            <option value="">全部</option>
            <#list Status as status>
                <option value="${status}" <#if status==''>selected</#if>>${status.title}</option>
            </#list>
        </select>
        <button onclick="search()" id="search_btn" class="btn btn-info">立即查询</button>
    </div>


    <table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
           lay-filter="tableFilter">

    </table>
</div>


</body>
<style>

</style>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="translation">评论语</a>
    <a class="layui-btn layui-btn-xs" lay-event="task">加载任务池</a>
    <a class="layui-btn layui-btn-xs" lay-event="collection">收退款</a>
    <a class="layui-btn layui-btn-xs" lay-event="copyData">复制</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="export">导出</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

</script>


<!--请在下方写此页面业务相关的脚本-->
<#--<script type="text/html" id="switchTpl">
    <!-- 这里的 checked 的状态只是演示 &ndash;&gt;
    <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="上架|下架" lay-filter="sexDemo" {{
           d.status== '1' ? 'checked' : '' }}>

</script>-->

<script type="text/html" id="switchTpl">
    <form class="layui-form" action="" lay-filter="tableData" style="margin: 0 auto;">
        <input type="radio" name="enable" value="1" data-id="{{d.id}}" title="上架" lay-filter="enableFilter" {{ d.status == 1 ? 'checked' : '' }}>
        <input type="radio" name="enable" value="2" data-id="{{d.id}}" title="待上架" lay-filter="enableFilter" {{ d.status == 2 ? 'checked' : '' }}>
        <input type="radio" name="enable" value="0" data-id="{{d.id}}" title="下架" lay-filter="enableFilter" {{ d.status == 0 ? 'checked' : '' }}>
       </form>
</script>

<script type="text/javascript">
    var startDate = "";
    var endDate = "";
    var searchKey = "";
    var marketId = "";
    var tableIns;
    var ids = "";
    var form;
    var table = "tb_task_comments";

    layui.use('table', function () {
        tableIns = layui.table,
            form = layui.form;
        tableIns.render({
            elem: '#layTable'
            ,
            url: '/sys/comments/data'
            ,
            where: {
                // orderBy: 'order by create_time desc',
                // table: table,
                // query: {'name': '', 'id': ''},
                // time: {'start': startDate, 'end': endDate},
                // key: {'name': searchKey},
            }
            ,
            toolbar: true,
            method: 'POST'
            ,
            id: 'dataTableId'
            ,
            cols: [[
                {type: 'checkbox', field: 'id',}
                , {
                    field: 'enable',
                    title: '上架状态',
                    width: 200,
                    align: 'center',
                    sort: true,
                    templet: '#switchTpl',
                    unresize: true
                }, {
                    field: 'title',
                    title: '任务标题',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'todayAmount',
                    title: '今日完成数',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'failCount',
                    title: '任务失败功数',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'successCount',
                    title: '任务成功数',
                    width: 150,
                    align: 'center',
                    sort: true
                }, {
                    field: 'amount',
                    title: '每日量',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'total',
                    title: '总量',
                    width: 150,
                    align: 'center',
                    sort: true
                },{
                    field: 'brand',
                    title: '渠道',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'gmt_created', title: '创建时间', templet: function (data) {
                        return dateFormat(data.createTime);
                    }, align: 'center', width: 200, sort: true
                }
                , {
                    field: 'gmt_modified', title: '修改时间', templet: function (data) {
                        return dateFormat(data.modifyTime);
                    }, align: 'center', width: 200, sort: true
                }, {
                    field: 'increase',
                    title: '单价用户',
                    width: 150,
                    align: 'center',
                    sort: true
                }, {
                    field: 'worth',
                    title: '客户单价',
                    width: 150,
                    align: 'center',
                    sort: true
                }, {
                    field: 'brand',
                    title: '渠道',
                    width: 150,
                    align: 'center',
                    sort: true
                }, {
                    field: 'sort',
                    title: '排序',
                    width: 150,
                    align: 'center',
                    sort: true
                }, {
                    field: 'label',
                    title: '副标题',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 400, align: 'center'}
            ]]
            ,
            page: true
        });

        form.on('radio(enableFilter)', function (obj) {
            updateEnable(obj.elem.getAttribute("data-id"),this.value);
            //commonenable(obj.elem.getAttribute("data-id"),this.value);
        });
        tableIns.on('checkbox(tableFilter)', function (obj) {
            var checkStatus = tableIns.checkStatus('dataTableId');
            var dataList = checkStatus.data;
            if (dataList != null && dataList.length > 0) {

                for (var i = 0; i < dataList.length; i++) {
                    ids += dataList[i].id + ",";
                }
            }
        });

        function deleteId(ids) {
            if (ids != "") {
                $.ajax({
                    url: "/sys/comments/del",
                    type: 'post',
                    data: {"table": table, "ids": ids},
                    async: false,
                    dataType: "json",
                    success: function (arg) {
                        if (arg) {
                            layer.msg(arg.message);
                            search();
                        } else {
                            layer.msg(arg.message);
                        }
                    }
                });
            }
        }

        function sts() {
            var sta = $("#status").val();
            tableIns.reload('dataTableId', {
                where: {status:sta},
                page: {
                    curr: 1
                }
            });
        }

        $("#multiDelete").click(function () {
            deleteId(ids)
        });

        tableIns.on('tool(tableFilter)', function (obj) {
            var data = obj.data;


            if (obj.event === 'translation') {
                layer_show("修改", "/sys/comments/translation?id=" + data.id, "850", "600");
            } else if (obj.event === 'del') {
                if (data.hasDeleted == 1) {
                    layer.msg('已删除，不可进行该操作!', {icon: 1, time: 1000});
                    return;
                }
                layer.confirm('真的删除行么', function (index) {
                    deleteId(data.id)
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer_show("修改", "/sys/comments/edit?id=" + data.id, "700", "600");
            } else if (obj.event === 'collection') {
                layer_show("收退款创建", "/financeRecord/edit?taskId=" + data.taskId + "&category=Comments" + "&custom_id=" + data.custom, "900", "600");
            } else if (obj.event === 'task') {
                task(data.taskId);
            }else if(obj.event ==='export'){
                exports(data.taskId)
            }else if(obj.event === 'copyData'){
                layer_show("新增", "/sys/comments/copyDatao?id=" + data.id, "700", "600");
            }
        });
    });

    function task(taskId) {
        $.ajax({
            url: "/sys/comments/reload",
            type: 'post',
            data: {"taskId": taskId},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }

    function search() {
        var sta = $("#status").val();
        tableIns.reload('dataTableId', {
            where: {
                status:sta
                // table: table,
                // query: {'name': ''},
                // time: {'start': startDate, 'end': endDate},
                // key: {'name': searchKey}
            }
            , page: {}
        });
    }


    function gradeEdit() {
        layer_show("新增", "/sys/comments/edit", "700", "600");
    }

    function showmsg(msg) {
        layer.msg(msg)
    }

    // 导出
    var exports = function (taskid) {
        layer.open({
            type: 2,
            area: ['600px', '500px'],
            fix: false, //不固定
            maxmin: true,
            shade: 0.4,
            title: '导出',
            content: '/export/excel/list?taskId='+taskid
        });
    };
    function commonenable(id, status) {
        $.ajax({
            url: "/common/commonSwitch",
            type: 'post',
            data: {"table": table, "id": id, "status": status, "feild": "status"},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }
    function updateEnable(id, status) {
        $.ajax({
            url: "/sys/comments/commonSwitch",
            type: 'post',
            data: {"id": id, "status": status},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }

    function checkData() {
        $.ajax({
            url: "/sys/comments/checkData",
            type: 'post',
            data: {},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }

</script>
<!--/请在上方写此页面业务相关的脚本-->
